// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]
#![no_implicit_prelude]
extern crate bytes;
extern crate serde;
extern crate serde_json;
extern crate serde_with;
extern crate std;
extern crate wkt;

mod debug;
mod deserialize;
mod serialize;

/// Message used by AlloyDB connectors to exchange client and connection metadata
/// with the server after a successful TLS handshake. This metadata includes an
/// IAM token, which is used to authenticate users based on their IAM identity.
/// The sole purpose of this message is for the use of AlloyDB connectors.
/// Clients should not rely on this message directly as there can be breaking
/// changes in the future.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct MetadataExchangeRequest {
    /// Optional. Connector information.
    pub user_agent: std::string::String,

    /// Authentication type.
    pub auth_type: crate::model::metadata_exchange_request::AuthType,

    /// IAM token used for both IAM user authentiation and
    /// `alloydb.instances.connect` permission check.
    pub oauth2_token: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl MetadataExchangeRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [user_agent][crate::model::MetadataExchangeRequest::user_agent].
    pub fn set_user_agent<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.user_agent = v.into();
        self
    }

    /// Sets the value of [auth_type][crate::model::MetadataExchangeRequest::auth_type].
    pub fn set_auth_type<
        T: std::convert::Into<crate::model::metadata_exchange_request::AuthType>,
    >(
        mut self,
        v: T,
    ) -> Self {
        self.auth_type = v.into();
        self
    }

    /// Sets the value of [oauth2_token][crate::model::MetadataExchangeRequest::oauth2_token].
    pub fn set_oauth2_token<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.oauth2_token = v.into();
        self
    }
}

impl wkt::message::Message for MetadataExchangeRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.alloydb.connectors.v1.MetadataExchangeRequest"
    }
}

/// Defines additional types related to [MetadataExchangeRequest].
pub mod metadata_exchange_request {
    #[allow(unused_imports)]
    use super::*;

    /// AuthType contains all supported authentication types.
    ///
    /// # Working with unknown values
    ///
    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
    /// additional enum variants at any time. Adding new variants is not considered
    /// a breaking change. Applications should write their code in anticipation of:
    ///
    /// - New values appearing in future releases of the client library, **and**
    /// - New values received dynamically, without application changes.
    ///
    /// Please consult the [Working with enums] section in the user guide for some
    /// guidelines.
    ///
    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
    #[derive(Clone, Debug, PartialEq)]
    #[non_exhaustive]
    pub enum AuthType {
        /// Authentication type is unspecified and DB_NATIVE is used by default
        Unspecified,
        /// Database native authentication (user/password)
        DbNative,
        /// Automatic IAM authentication
        AutoIam,
        /// If set, the enum was initialized with an unknown value.
        ///
        /// Applications can examine the value using [AuthType::value] or
        /// [AuthType::name].
        UnknownValue(auth_type::UnknownValue),
    }

    #[doc(hidden)]
    pub mod auth_type {
        #[allow(unused_imports)]
        use super::*;
        #[derive(Clone, Debug, PartialEq)]
        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
    }

    impl AuthType {
        /// Gets the enum value.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the string representation of enums.
        pub fn value(&self) -> std::option::Option<i32> {
            match self {
                Self::Unspecified => std::option::Option::Some(0),
                Self::DbNative => std::option::Option::Some(1),
                Self::AutoIam => std::option::Option::Some(2),
                Self::UnknownValue(u) => u.0.value(),
            }
        }

        /// Gets the enum value as a string.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the integer representation of enums.
        pub fn name(&self) -> std::option::Option<&str> {
            match self {
                Self::Unspecified => std::option::Option::Some("AUTH_TYPE_UNSPECIFIED"),
                Self::DbNative => std::option::Option::Some("DB_NATIVE"),
                Self::AutoIam => std::option::Option::Some("AUTO_IAM"),
                Self::UnknownValue(u) => u.0.name(),
            }
        }
    }

    impl std::default::Default for AuthType {
        fn default() -> Self {
            use std::convert::From;
            Self::from(0)
        }
    }

    impl std::fmt::Display for AuthType {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
            wkt::internal::display_enum(f, self.name(), self.value())
        }
    }

    impl std::convert::From<i32> for AuthType {
        fn from(value: i32) -> Self {
            match value {
                0 => Self::Unspecified,
                1 => Self::DbNative,
                2 => Self::AutoIam,
                _ => Self::UnknownValue(auth_type::UnknownValue(
                    wkt::internal::UnknownEnumValue::Integer(value),
                )),
            }
        }
    }

    impl std::convert::From<&str> for AuthType {
        fn from(value: &str) -> Self {
            use std::string::ToString;
            match value {
                "AUTH_TYPE_UNSPECIFIED" => Self::Unspecified,
                "DB_NATIVE" => Self::DbNative,
                "AUTO_IAM" => Self::AutoIam,
                _ => Self::UnknownValue(auth_type::UnknownValue(
                    wkt::internal::UnknownEnumValue::String(value.to_string()),
                )),
            }
        }
    }

    impl serde::ser::Serialize for AuthType {
        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
        where
            S: serde::Serializer,
        {
            match self {
                Self::Unspecified => serializer.serialize_i32(0),
                Self::DbNative => serializer.serialize_i32(1),
                Self::AutoIam => serializer.serialize_i32(2),
                Self::UnknownValue(u) => u.0.serialize(serializer),
            }
        }
    }

    impl<'de> serde::de::Deserialize<'de> for AuthType {
        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
        where
            D: serde::Deserializer<'de>,
        {
            deserializer.deserialize_any(wkt::internal::EnumVisitor::<AuthType>::new(
                ".google.cloud.alloydb.connectors.v1.MetadataExchangeRequest.AuthType",
            ))
        }
    }
}

/// Message for response to metadata exchange request. The sole purpose of this
/// message is for the use of AlloyDB connectors. Clients should not rely on this
/// message directly as there can be breaking changes in the future.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct MetadataExchangeResponse {
    /// Response code.
    pub response_code: crate::model::metadata_exchange_response::ResponseCode,

    /// Optional. Error message.
    pub error: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl MetadataExchangeResponse {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [response_code][crate::model::MetadataExchangeResponse::response_code].
    pub fn set_response_code<
        T: std::convert::Into<crate::model::metadata_exchange_response::ResponseCode>,
    >(
        mut self,
        v: T,
    ) -> Self {
        self.response_code = v.into();
        self
    }

    /// Sets the value of [error][crate::model::MetadataExchangeResponse::error].
    pub fn set_error<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.error = v.into();
        self
    }
}

impl wkt::message::Message for MetadataExchangeResponse {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.alloydb.connectors.v1.MetadataExchangeResponse"
    }
}

/// Defines additional types related to [MetadataExchangeResponse].
pub mod metadata_exchange_response {
    #[allow(unused_imports)]
    use super::*;

    /// Response code.
    ///
    /// # Working with unknown values
    ///
    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
    /// additional enum variants at any time. Adding new variants is not considered
    /// a breaking change. Applications should write their code in anticipation of:
    ///
    /// - New values appearing in future releases of the client library, **and**
    /// - New values received dynamically, without application changes.
    ///
    /// Please consult the [Working with enums] section in the user guide for some
    /// guidelines.
    ///
    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
    #[derive(Clone, Debug, PartialEq)]
    #[non_exhaustive]
    pub enum ResponseCode {
        /// Unknown response code
        Unspecified,
        /// Success
        Ok,
        /// Failure
        Error,
        /// If set, the enum was initialized with an unknown value.
        ///
        /// Applications can examine the value using [ResponseCode::value] or
        /// [ResponseCode::name].
        UnknownValue(response_code::UnknownValue),
    }

    #[doc(hidden)]
    pub mod response_code {
        #[allow(unused_imports)]
        use super::*;
        #[derive(Clone, Debug, PartialEq)]
        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
    }

    impl ResponseCode {
        /// Gets the enum value.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the string representation of enums.
        pub fn value(&self) -> std::option::Option<i32> {
            match self {
                Self::Unspecified => std::option::Option::Some(0),
                Self::Ok => std::option::Option::Some(1),
                Self::Error => std::option::Option::Some(2),
                Self::UnknownValue(u) => u.0.value(),
            }
        }

        /// Gets the enum value as a string.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the integer representation of enums.
        pub fn name(&self) -> std::option::Option<&str> {
            match self {
                Self::Unspecified => std::option::Option::Some("RESPONSE_CODE_UNSPECIFIED"),
                Self::Ok => std::option::Option::Some("OK"),
                Self::Error => std::option::Option::Some("ERROR"),
                Self::UnknownValue(u) => u.0.name(),
            }
        }
    }

    impl std::default::Default for ResponseCode {
        fn default() -> Self {
            use std::convert::From;
            Self::from(0)
        }
    }

    impl std::fmt::Display for ResponseCode {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
            wkt::internal::display_enum(f, self.name(), self.value())
        }
    }

    impl std::convert::From<i32> for ResponseCode {
        fn from(value: i32) -> Self {
            match value {
                0 => Self::Unspecified,
                1 => Self::Ok,
                2 => Self::Error,
                _ => Self::UnknownValue(response_code::UnknownValue(
                    wkt::internal::UnknownEnumValue::Integer(value),
                )),
            }
        }
    }

    impl std::convert::From<&str> for ResponseCode {
        fn from(value: &str) -> Self {
            use std::string::ToString;
            match value {
                "RESPONSE_CODE_UNSPECIFIED" => Self::Unspecified,
                "OK" => Self::Ok,
                "ERROR" => Self::Error,
                _ => Self::UnknownValue(response_code::UnknownValue(
                    wkt::internal::UnknownEnumValue::String(value.to_string()),
                )),
            }
        }
    }

    impl serde::ser::Serialize for ResponseCode {
        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
        where
            S: serde::Serializer,
        {
            match self {
                Self::Unspecified => serializer.serialize_i32(0),
                Self::Ok => serializer.serialize_i32(1),
                Self::Error => serializer.serialize_i32(2),
                Self::UnknownValue(u) => u.0.serialize(serializer),
            }
        }
    }

    impl<'de> serde::de::Deserialize<'de> for ResponseCode {
        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
        where
            D: serde::Deserializer<'de>,
        {
            deserializer.deserialize_any(wkt::internal::EnumVisitor::<ResponseCode>::new(
                ".google.cloud.alloydb.connectors.v1.MetadataExchangeResponse.ResponseCode",
            ))
        }
    }
}
